/*
test_init.c
test for index init:
1)idx_init(CREATE)
2)idx_exit()
*/

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "defines.h"
#include "index.h"

int main()
{
	char *g_image=NULL;
	INIT_TYPE init_type;
	STATE state;

	sync_init("/tmp/disk","sync.log");

	g_image=(char*)mp_alloc(IMAGE_K_SIZE*1024);
	state=idx_init(INIT_TYPE_CREATE, g_image, "index_1.log", 5*1024*64);
	printf ("index_init_done\n");
	fflush(stdout);
	printf ("exiting...\n");

	idx_exit();	
	sync_exit();
	mp_free(g_image);

	printf ("ok.\n");
	fflush(stdout);

/*************************************************************************************/

	sync_init("/tmp/disk", "sync.log");
	g_image=(char*)mp_alloc(IMAGE_K_SIZE*1024);
	idx_init(INIT_TYPE_LOAD, g_image, "index_2.log", 5*1024*64);
	printf ("index_init_done\n");
	fflush(stdout);

	idx_exit();
	sync_exit();
	mp_free(g_image);

	return 0;

}

